/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * File Name          : freertos.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2025 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "usr_inc.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */

/* USER CODE END Variables */
/* Definitions for defaultTask */
osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
  .name = "defaultTask",
  .stack_size = 400 * 4,
  .priority = (osPriority_t) osPriorityLow,
};
/* Definitions for dji4Exe */
osThreadId_t dji4ExeHandle;
const osThreadAttr_t dji4Exe_attributes = {
  .name = "dji4Exe",
  .stack_size = 240 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for dribblePrintf */
osThreadId_t dribblePrintfHandle;
const osThreadAttr_t dribblePrintf_attributes = {
  .name = "dribblePrintf",
  .stack_size = 400 * 4,
  .priority = (osPriority_t) osPriorityLow7,
};
/* Definitions for drbbleUpdate */
osThreadId_t drbbleUpdateHandle;
const osThreadAttr_t drbbleUpdate_attributes = {
  .name = "drbbleUpdate",
  .stack_size = 240 * 4,
  .priority = (osPriority_t) osPriorityHigh,
};
/* Definitions for dji3Exe */
osThreadId_t dji3ExeHandle;
const osThreadAttr_t dji3Exe_attributes = {
  .name = "dji3Exe",
  .stack_size = 240 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for tossPrintf */
osThreadId_t tossPrintfHandle;
const osThreadAttr_t tossPrintf_attributes = {
  .name = "tossPrintf",
  .stack_size = 400 * 4,
  .priority = (osPriority_t) osPriorityLow7,
};
/* Definitions for tossUpdate */
osThreadId_t tossUpdateHandle;
const osThreadAttr_t tossUpdate_attributes = {
  .name = "tossUpdate",
  .stack_size = 240 * 4,
  .priority = (osPriority_t) osPriorityHigh,
};
/* Definitions for pidArgsQueue */
osMessageQueueId_t pidArgsQueueHandle;
const osMessageQueueAttr_t pidArgsQueue_attributes = {
  .name = "pidArgsQueue"
};
/* Definitions for dji4InfoBox */
osMessageQueueId_t dji4InfoBoxHandle;
const osMessageQueueAttr_t dji4InfoBox_attributes = {
  .name = "dji4InfoBox"
};
/* Definitions for dribbleCmdQueue */
osMessageQueueId_t dribbleCmdQueueHandle;
const osMessageQueueAttr_t dribbleCmdQueue_attributes = {
  .name = "dribbleCmdQueue"
};
/* Definitions for dji3InfoBox */
osMessageQueueId_t dji3InfoBoxHandle;
const osMessageQueueAttr_t dji3InfoBox_attributes = {
  .name = "dji3InfoBox"
};
/* Definitions for tossCmdQueue */
osMessageQueueId_t tossCmdQueueHandle;
const osMessageQueueAttr_t tossCmdQueue_attributes = {
  .name = "tossCmdQueue"
};
/* Definitions for tossStrokeQueue */
osMessageQueueId_t tossStrokeQueueHandle;
const osMessageQueueAttr_t tossStrokeQueue_attributes = {
  .name = "tossStrokeQueue"
};
/* Definitions for djiMutex */
osMutexId_t djiMutexHandle;
const osMutexAttr_t djiMutex_attributes = {
  .name = "djiMutex"
};

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */

/* USER CODE END FunctionPrototypes */

void StartDefaultTask(void *argument);
extern void StartDji4Exe(void *argument);
extern void StartDribblePrintf(void *argument);
extern void StartDribbleUpdate(void *argument);
extern void StartDji3Exe(void *argument);
extern void StartTossPrintf(void *argument);
extern void StartTossUpdate(void *argument);

void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */

/**
  * @brief  FreeRTOS initialization
  * @param  None
  * @retval None
  */
void MX_FREERTOS_Init(void) {
  /* USER CODE BEGIN Init */

  /* USER CODE END Init */
  /* Create the mutex(es) */
  /* creation of djiMutex */
  djiMutexHandle = osMutexNew(&djiMutex_attributes);

  /* USER CODE BEGIN RTOS_MUTEX */
  /* add mutexes, ... */
  /* USER CODE END RTOS_MUTEX */

  /* USER CODE BEGIN RTOS_SEMAPHORES */
  /* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */

  /* USER CODE BEGIN RTOS_TIMERS */
  /* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */

  /* Create the queue(s) */
  /* creation of pidArgsQueue */
  pidArgsQueueHandle = osMessageQueueNew (8, sizeof(PidArgsMsg_t), &pidArgsQueue_attributes);

  /* creation of dji4InfoBox */
  dji4InfoBoxHandle = osMessageQueueNew (1, sizeof(DjiMsg_t), &dji4InfoBox_attributes);

  /* creation of dribbleCmdQueue */
  dribbleCmdQueueHandle = osMessageQueueNew (8, sizeof(DribbleCmdMsg_t), &dribbleCmdQueue_attributes);

  /* creation of dji3InfoBox */
  dji3InfoBoxHandle = osMessageQueueNew (1, sizeof(DjiMsg_t), &dji3InfoBox_attributes);

  /* creation of tossCmdQueue */
  tossCmdQueueHandle = osMessageQueueNew (8, sizeof(TossCmdMsg_t), &tossCmdQueue_attributes);

  /* creation of tossStrokeQueue */
  tossStrokeQueueHandle = osMessageQueueNew (8, sizeof(float), &tossStrokeQueue_attributes);

  /* USER CODE BEGIN RTOS_QUEUES */
  /* add queues, ... */
  /* USER CODE END RTOS_QUEUES */

  /* Create the thread(s) */
  /* creation of defaultTask */
  defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);

  /* creation of dji4Exe */
  dji4ExeHandle = osThreadNew(StartDji4Exe, NULL, &dji4Exe_attributes);

  /* creation of dribblePrintf */
  dribblePrintfHandle = osThreadNew(StartDribblePrintf, NULL, &dribblePrintf_attributes);

  /* creation of drbbleUpdate */
  drbbleUpdateHandle = osThreadNew(StartDribbleUpdate, NULL, &drbbleUpdate_attributes);

  /* creation of dji3Exe */
  dji3ExeHandle = osThreadNew(StartDji3Exe, NULL, &dji3Exe_attributes);

  /* creation of tossPrintf */
  tossPrintfHandle = osThreadNew(StartTossPrintf, NULL, &tossPrintf_attributes);

  /* creation of tossUpdate */
  tossUpdateHandle = osThreadNew(StartTossUpdate, NULL, &tossUpdate_attributes);

  /* USER CODE BEGIN RTOS_THREADS */
  /* add threads, ... */
  /* USER CODE END RTOS_THREADS */

  /* USER CODE BEGIN RTOS_EVENTS */
  /* add events, ... */
  /* USER CODE END RTOS_EVENTS */

}

/* USER CODE BEGIN Header_StartDefaultTask */
/**
  * @brief  Function implementing the defaultTask thread.
  * @param  argument: Not used
  * @retval None
  */
/* USER CODE END Header_StartDefaultTask */
__weak void StartDefaultTask(void *argument)
{
  /* USER CODE BEGIN StartDefaultTask */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END StartDefaultTask */
}

/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */

/* USER CODE END Application */

